﻿


using System.Collections.Generic;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Audio;

namespace projetSupinfoBFG.Base
{
    class RessourcesManager
    {
        ContentManager content;

        #region Texture2D

        Dictionary<string, Texture2D> textureBank = new Dictionary<string, Texture2D>();

        public Texture2D GetTexture(string assetName)
        {
            if (textureBank.ContainsKey(assetName))
                return textureBank[assetName];
            else
            {
                textureBank.Add(assetName, content.Load<Texture2D>(assetName));
                return textureBank[assetName];
            }
        }
        
        #endregion

        #region SpriteFont

        Dictionary<string, SpriteFont> spritefontBank = new Dictionary<string, SpriteFont>();

        public SpriteFont GetSpriteFont(string assetName)
        {
            if (spritefontBank.ContainsKey(assetName))
                return spritefontBank[assetName];
            else
            {
                spritefontBank.Add(assetName, content.Load<SpriteFont>(assetName));
                return spritefontBank[assetName];
            }
        }

        #endregion

        #region SoundEffect

        Dictionary<string, SoundEffect> soundeffectBank = new Dictionary<string, SoundEffect>();

        public SoundEffect GetSoundEffect(string assetName)
        {
            if (soundeffectBank.ContainsKey(assetName))
                return soundeffectBank[assetName];
            else
            {
                soundeffectBank.Add(assetName, content.Load<SoundEffect>(assetName));
                return soundeffectBank[assetName];
            }
        }

        #endregion

        #region Singleton

        private static RessourcesManager _theUniqueInstance = null;

        private RessourcesManager(ContentManager content)
        {
            this.content = content;
        }

        public static RessourcesManager GetInstance(ContentManager content)
        {
            if (_theUniqueInstance == null)
                return _theUniqueInstance = new RessourcesManager(content);
            else
                return _theUniqueInstance;
        }

        public static RessourcesManager GetInstance()
        {
                return _theUniqueInstance;
        }

        #endregion
}
}





